package com.wsx.ones.monitor.core.executer;

import com.wsx.ones.monitor.common.util.FinalStaticUtil;

import java.util.concurrent.*;

/**
 * 实现自己的线程池实现类
 * Created by wangshuaixin on 17/2/6.
 */
public class RpcExecuter {

    /**
     * 线程池的实现类
     * @param coreThreads 核心线程数
     * @param maxThreads 最大线程数
     * @param queues 队列的大小
     * @return
     */
    public static ThreadPoolExecutor getExecuter(int coreThreads, int maxThreads, int queues) {
        return new ThreadPoolExecutor(coreThreads,maxThreads,0, TimeUnit.MILLISECONDS,
                            queues == 0 ? (new SynchronousQueue<Runnable>())
                                        : (queues > 0 ? new LinkedBlockingQueue<Runnable>(queues)
                                                        : new LinkedBlockingQueue<Runnable>()
                                            ),
                            new RpcThreadFactory(FinalStaticUtil.RPC_THREAD_FACTORY),
                            new RpcRejectedExecutionHandler(FinalStaticUtil.RPC_THREAD_FACTORY));
    }
}
